﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeiDuan.Model;
using WeiDuan.Service;
using B2B.Service;
using B2B.Business;
using B2B.Business.Impl;
using Autofac;

namespace B2B.Service.Impl
{
    [WeiDuanService(Name = "B2B.CartService", Description = "购物车管理")]
    public class CartService:BaseService,ICartService,IAppService
    {
        public ICartBusiness mBusiness = null;

        public CartService()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<B2B.Business.Impl.CartBusiness>().As<ICartBusiness>();
            using (var container = builder.Build())
            {
                mBusiness = container.Resolve<ICartBusiness>();
            }
            base.eventCreate+=CartService_eventCreate;
        }

        private void CartService_eventCreate(IWeiDuanService service)
        {
            if (mBusiness is IServiceInjection)
                ((IServiceInjection)mBusiness).Injection(mWeiDuanService);
        }

        [WeiDuanInterface(Name = "Add", Description = "添加商品到购物车")]
        public void Add(ProductCartAddRequest req, UserInfo user)
        {
            mBusiness.Add(req, user);
        }

        [WeiDuanInterface(Name = "AddBatch", Description = "批量添加商品到购物车")]
        public void AddBatch(List<ProductCartAddRequest> req, UserInfo user)
        {
            mBusiness.AddBatch(req, user);
        }

        [WeiDuanInterface(Name = "Update", Description = "修改购物车中的商品")]
        public void Update(ProductCartUpdateRequest req, UserInfo user)
        {
            mBusiness.Update(req, user);
        }

        [WeiDuanInterface(Name = "Remove", Description = "删除一笔购物车中的商品")]
        public void Remove(string id, UserInfo user)
        {
            mBusiness.Remove(id, user);
        }

        [WeiDuanInterface(Name = "RemoveAll", Description = "清除购物车中所有的商品")]
        public void RemoveAll(UserInfo user)
        {
            mBusiness.RemoveAll(user);
        }

        [WeiDuanInterface(Name = "Query", Description = "查询购物车中的商品清单")]
        public List<CartItemInfo> Query(UserInfo user)
        {
            return mBusiness.Query(user);
        }
    }
}
